package com.cyz.admin.controller;

import com.cyz.admin.service.PathCardService;
import com.cyz.common.dto.PathCardDto;
import com.cyz.common.dto.PathDto;
import com.cyz.admin.service.PathService;
import com.cyz.common.utils.R;
import com.cyz.common.validated.AddGroup;
import com.cyz.common.validated.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

//TODO: 权限管理没做

@Api(tags = "管理端资源学习路线相关接口")
@RestController
@RequestMapping("/path")
public class PathController {

    @Autowired
    private PathService pathService;
    @Autowired
    private PathCardService pathCardService;

    @PreAuthorize("@ps.hasPermission('contant:path:button')")
    @ApiOperation(value = "查询学习路径")
    @GetMapping("/queryPaths")
    public R queryPaths(){
        return pathService.queryPath();
    }

    @PreAuthorize("@ps.hasPermission('contant:path:button')")
    @ApiOperation(value = "更新学习路径")
    @PutMapping("/updatePath")
    public R updatePath(@RequestBody PathDto pathDto){
        return pathService.updatePath(pathDto);
    }

    @PreAuthorize("@ps.hasPermission('contant:path:button')")
    @ApiOperation(value = "增加学习路径")
    @PostMapping("/addPath")
    public R addPath(@RequestBody PathDto pathDto){
        return pathService.addPath(pathDto);
    }

    @PreAuthorize("@ps.hasPermission('contant:path:button')")
    @ApiOperation(value = "删除学习路径")
    @DeleteMapping("/deletePaths")
    public R deletePaths(Integer[] ids){
        return pathService.deletePaths(ids);
    }

    @PreAuthorize("@ps.hasPermission('contant:path:list')")
    @ApiOperation(value = "查询课程及其学习路径")
    @GetMapping("/queryCardsAndPath")
    public R queryCardsAndPath(){
        return pathCardService.queryCardsAndPath();
    }

    @PreAuthorize("@ps.hasPermission('contant:path:list')")
    @ApiOperation(value = "添加课程及其学习路径")
    @PostMapping("/addPathCard")
    public R addPathCard(@Validated(AddGroup.class) @RequestBody PathCardDto pathCardDto){
        return pathCardService.addPathCard(pathCardDto);
    }

    @PreAuthorize("@ps.hasPermission('contant:path:list')")
    @ApiOperation(value = "`更新课程及其学习路径")
    @PutMapping("/updatePathCard")
    public R updatePathCard(@Validated(UpdateGroup.class) @RequestBody PathCardDto pathCardDto){
        return pathCardService.updatePathCard(pathCardDto);
    }

    @PreAuthorize("@ps.hasPermission('contant:path:list')")
    @ApiOperation(value = "删除课程及其学习路径")
    @DeleteMapping("/deletePathCards")
    public R deletePathCards(Integer[] ids){
        return pathCardService.deletePathCards(ids);
    }
}
